<style>
    .th-title { background: #f4f4f4; text-align: center; }
    .btn.btn-primary, .btn.btn-primary:hover { background-color: #008678; border-color: #008678; }
</style>

<div style="margin-bottom: 20px;">
    <form method="get" action="/oss/">
        <input type="hidden" name="r" value="<{$beforeAction.Current.Route}>"/>
        <input type="hidden" name="m" value="<{$beforeAction.Current.MenuID}>"/>
        <input type="hidden" name="g" value="<{$beforeAction.Current.GameSrc}>"/>
        <input type="hidden" name="p" value="<{$beforeAction.Current.Platform}>"/>

        <div class="form-group">
            <label for="exampleInputFile">服务器</label>
            <select class="form-control" name="server">
                <{html_options options=$serverList selected=$server}>
            </select>
        </div>

        <div class="form-group">
            <label for="exampleInputFile">角色ID/角色名称</label>
            <input type="text" class="form-control" name="search" value="<{$search}>">
        </div>

        <button class="btn btn-default btn-flat" type="submit">查询</button>
    </form>
</div>

<{if !empty($role)}>
    <{if $role.state}>

    <div class="box box-black">
        <div class="box-body">
            <table class="table table-bordered">
                <colgroup>
                    <col style="width: 10%;"></col>
                    <col style="width: 15%;"></col>
                    <col style="width: 10%;"></col>
                    <col style="width: 15%;"></col>
                    <col style="width: 10%;"></col>
                    <col style="width: 15%;"></col>
                    <col style="width: 10%;"></col>
                    <col style="width: 15%;"></col>
                </colgroup>
                <tr>
                    <th class="th-label-s">账号名称</th>
                    <td><{$role.data.accountName}></td>
                    <th class="th-label-s">角色ID</th>
                    <td><{$role.data.roleId}></td>
                    <th class="th-label-s">角色名称</th>
                    <td><{$role.data.roleName}></td>
                    <th class="th-label-s">性别</th>
                    <td><{$role.data.occupation}></td>
                </tr>

                <tr>
                    <th class="th-label-s">等级</th>
                    <td><{$role.data.nLevel}></td>
                    <th class="th-label-s">转生等级</th>
                    <td><{$role.data.bTransLv}></td>
                    <th class="th-label-s">PVP等级</th>
                    <td><{$role.data.bpvpLv}></td>
                    <th class="th-label-s">VIP等级</th>
                    <td><{$role.data.Vip}></td>
                </tr>

                <tr>
                    <th class="th-label-s">勾玉</th>
                    <td><{$role.data.iMoney}></td>
                    <th class="th-label-s">石币</th>
                    <td><{$role.data.iGold}></td>
                    <th class="th-label-s">珍珠</th>
                    <td><{$role.data.iConch}></td>
                    <th class="th-label-s">公平竞技场积分</th>
                    <td><{$role.data.FairScore}></td>
                </tr>

                <tr>
                    <th class="th-label-s">当前主线ID</th>
                    <td><{$role.data.CurQuestId}></td>
                    <th class="th-label-s">是否在线</th>
                    <td><{$role.data.isOnline}></td>
                    <th class="th-label-s">创建角色时间</th>
                    <td><{$role.data.iCreateTime}></td>
                    <th class="th-label-s">最后登录时间</th>
                    <td><{$role.data.dwLastLogInTime}></td>
                </tr>

            </table>
        </div>

        <div class="box-footer">
            <div class="row">
                <div class="col-md-2"><button type="button" val="PropsDetail" class="btn btn-block btn-default extra-btn">道具查询</button></div>
                <div class="col-md-2"><button type="button" val="TaskDetail" class="btn btn-block btn-default extra-btn">任务查询</button></div>
                <div class="col-md-2"><button type="button" val="StageDetail" class="btn btn-block btn-default extra-btn">关卡查询</button></div>
                <div class="col-md-2"><button type="button" val="PetDetail" class="btn btn-block btn-default extra-btn">宠物查询</button></div>
            </div>
        </div>
    </div>

    <div id="extra-box" class="box box-black">
        <div class="box-header">
            <h5 class="box-title"></h5>
        </div>
        <div class="box-body">
            <table class="table table-bordered">

            </table>
        </div>
    </div>

    <{else}>
    <div class="alert alert-warning" style="margin:0;" role="alert"><{$role.msg}></div>
    <{/if}>
<{/if}>


<script type="text/javascript">
    $(function(){
        var extraBox = $('#extra-box'),
            extraTable = extraBox.find("table"),
            cache = { };

        extraBox.hide();

        $(".extra-btn").click(function(){
            var url     = '<{$extra_url nofilter}>',
                roleId  = '<{$role.data.roleId}>',
                server  = '<{$server}>',
                type    = $(this).attr('val');

            extraBox.find('.box-title').html($(this).html());

            $(".extra-btn").removeClass('btn-primary').addClass('btn-default');
            $(this).removeClass('btn-default').addClass('btn-primary');

            if(cache[type]){
                show(cache[type]);
            }else{
                $.getJSON(url, { role:roleId, type: type, server: server }, function(rs){
                    if(rs['state']){
                        cache[type] = rs;
                        show(rs);
                    }else{
                        alert(rs['msg']);
                    }
                });
            }
        });

        function show(rs){
            extraBox.show();

            extraTable.html('');

            var thead = '<tr>';
            for(var i in rs['desc']){
                thead += '<th class="th-title">'+rs['desc'][i]+'</th>';
            }
            thead += '</tr>';

            var tbody = '';
            for(var i in rs['data']){
                tbody += '<tr>'
                for(var j in rs['desc']){
                    tbody += '<td for="'+j+'">'+((rs['data'][i][j] == null) ? '' : rs['data'][i][j])+'</td>'
                }
                tbody += '</tr>'
            }

            extraTable.append(thead);
            extraTable.append(tbody);
        }
    });
</script>